<?php
/**
 * 首页
 * 
 * @version $Id$
 */

class Module_home
{
	/**
	 * 构造函数
	 */
	function __construct() {
		
	}

	/**
	 * 默认 action
	 */
	function index() {
		$smarty = loadSmarty();
		$uin = SessionInfo('uin');
		
		// 需要获取的用户数据
		$uins_arr = array($uin);
		
		// 获取主人用户信息
		loadLib('User');
		$userinfo = User::getBaseInfo($uin);
		$user_logo = User::getLogo($userinfo);
		//print_r($user_logo);
		$smarty->assign('user_logo' , $user_logo);
		$smarty->assign('userinfo' , $userinfo);
		
		// 获取自己所有好友
		// loadLib('Friend');
		// $friends_arr = Friend::get($uin);
		
		// 获取系统消息最新数字
		loadLib('SysMsg');
		$sysmsg_unread_num = SysMsg::getUnreadNum( $uin );
		$smarty->assign('sysmsg_unread_num' , $sysmsg_unread_num);
		
		// 获取金库
		loadLib('Money');
		$money = Money::get( $uin );
		$money_str = Money::toString($money);
		$smarty->assign('money' , $money);
		$smarty->assign('money_str' , $money_str);
		
		// 获取feed ，获取所有人的feed
		loadLib('Feed');
		// $get_feeds_uins = $friends_arr;
		// $get_feeds_uins[] = $uin;
		$feeds = Feed::getAllList( 0 , 11 );		// 多取一条，为了判断是否有更多feed
		foreach($feeds as $k => $feed) {
			$feeds[$k]['data'] = unserialize($feed['data']);
			
			$uins_arr[] = $feed['uin'];
		}
		
		// 处理用户数据
		loadLib('User');
		$uins_info = User::getBaseInfo($uins_arr);
		
		function feedFormatContent($feed) {
			return Feed::formatContent($feed);
		}
		// $smarty->registerPlugin('modifier' , 'feedFormatContent' , 'Feed::formatContent');
		$smarty->assign('feeds' , $feeds);
		$smarty->assign('uins_info' , $uins_info);
		
		
		// 连续登陆奖励
		loadLib('Awards_Login');
		$awards_login = Awards_Login::getInfo($uin , true);
		$awards_money = Awards_Login::getAwardsMoney($awards_login['times']);
		$smarty->assign('awards_login' , $awards_login);
		$smarty->assign('awards_money' , $awards_money);
		
		header('Location: ' . SITEURL . '/app.php?m=overlordguide&sid=' . sessionInfo('skey') );
//		return $smarty->fetch('home/index.tpl.php');
	}
}

# end of script
